package com.uchedao.seller.ui.carlist.province_city;

import android.content.Intent;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;

import com.uchedao.seller.R;
import com.uchedao.seller.ui.carlist.BaseFragForBaidu;
import com.uchedao.seller.ui.carlist.db.CarDbHelper;
import com.uchedao.seller.ui.carlist.entity.CityEntity;
import com.uchedao.seller.ui.carlist.entity.ProvinceEntity;

import java.util.ArrayList;

/**
 * Created by ZhangZhanghua on 2015/10/29 0029.
 */
public class ProvinceCityFragment extends BaseFragForBaidu {
    private ListView provinceView;
    private ListView cityView;
    private ProvinceAdapter provinceAdapter;
    private CityAdapter cityAdapter;
    private ArrayList<ProvinceEntity> provinceList;
    private ArrayList<CityEntity> cityList;
    private int provinceId, cityId;
    private String provinceName, cityName;

    @Override
    protected String getActivityTag() {
        return "ProvinceCityFragment";
    }

    @Override
    public int getViewLayoutId() {
        return R.layout.fragment_province_city;
    }

    @Override
    public void initListener() {
        provinceView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                provinceId = provinceList.get(position).getId();
                provinceName =provinceList.get(position).getName();
                cityList = CarDbHelper.getCity(mContext, provinceId);
                cityAdapter = new CityAdapter(mContext,cityList,provinceName);
                cityView.setAdapter(cityAdapter);
                cityAdapter.notifyDataSetChanged();
            }
        });
    }

    @Override
    public void initData() {
        provinceList = CarDbHelper.getProvince(mContext);
        provinceAdapter = new ProvinceAdapter(mContext,provinceList);
        provinceView.setAdapter(provinceAdapter);
    }

    @Override
    public void initView() {
        provinceView = (ListView) findViewById(R.id.province_list);
        cityView = (ListView) findViewById(R.id.city_list);

    }

    @Override
    public void onActivityResultFragment(int requestCode, int resultCode, Intent data) {

    }
}
